package com.lx.others.web;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.lx.dm.entity.Product;
import com.lx.others.dao.ProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("product")
public class ProductDo {

    @Autowired
    ProductMapper productMapper;

    @RequestMapping("hots")
    public List<Product> hot(){
        LambdaQueryWrapper<Product> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Product::getIsHot, 1);
        Page page = new PageDTO(1, 10);
        return productMapper.selectPage(page, lqw).getRecords();
    }

    @RequestMapping("news")
    public List<Product> news(){
        LambdaQueryWrapper<Product> lqw = new LambdaQueryWrapper<>();
        lqw.orderByDesc(Product::getPid);
        Page page = new PageDTO(1, 10);
        return productMapper.selectPage(page, lqw).getRecords();
    }

    @RequestMapping("getProductById")
    public Product getProductById(Integer pid){
        LambdaQueryWrapper<Product> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Product::getPid, pid);
        return productMapper.selectOne(lqw);
    }
}
